package br.ufmg.dees.insane.commons.dialogs;

import javax.swing.table.AbstractTableModel;

public class OutputTableModel extends AbstractTableModel
{

  private static final long serialVersionUID = 1L;
  private int nRows;
  private int nColumns;
  private String[] columnNames;
  private Object[][] cells;

  public OutputTableModel(int nr, int nc, String[] colNames, String[][]c){
   this.nRows =nr;
   this.nColumns =nc;
   this.cells = new Object[nRows][nColumns];
	for(int i=0; i<nRows; i++)
		for(int j=0; j<nColumns; j++)
			cells[i][j] = (Object)c[i][j];
   this.columnNames = new String[nColumns];
	for(int i=0; i<nColumns;i++)
		columnNames[i] = colNames[i];
  }

  public OutputTableModel(int nr, int nc, String[] colNames, Object[][]c){
   this.nRows =nr;
   this.nColumns =nc;
   this.cells = new Object[nRows][nColumns];
	for(int i=0; i<nRows; i++)
		for(int j=0; j<nColumns; j++)
			cells[i][j] = c[i][j];
   this.columnNames = new String[nColumns];
	for(int i=0; i<nColumns;i++)
		columnNames[i] = colNames[i];
  }

  public OutputTableModel(int nr, int nc, String[] colNames){
   this.nRows =nr;
   this.nColumns =nc;
   this.cells = new Object[nRows][nColumns];
	for(int i=0; i<nRows; i++)
		for(int j=0; j<nColumns; j++)
			cells[i][j] = new Object();
   this.columnNames = new String[nColumns];
	for(int i=0; i<nColumns;i++)
		columnNames[i] = colNames[i];
  }

  public String getColumnName(int c)
   {  
     return columnNames[c];
   }

   public Class<?> getColumnClass(int c)
   {  
     	return cells[0][c].getClass();
   }

   public int getColumnCount()
   {  
     return cells[0].length;
   }

   public int getRowCount()
   { 
     return cells.length;
   }

   public Object getValueAt(int r, int c)
   {
	 return cells[r][c];
   }

   public void setValueAt(Object obj, int r, int c)
   {  cells[r][c] = obj;
   }

   public boolean isCellEditable(int r, int c)
   {  return false;
   }

   public void initOutputTable(Object[][] obj)
   {  	
	for(int i=0; i< cells.length; i++)	
		for(int j=0; j< cells[0].length; j++)	
		cells[i][j] = obj[i][j];
   }
	
   public void initOutputTableColumn(int c, Object[] obj)
   {  	
	for(int i=0; i< cells.length; i++)	
		cells[i][c] = obj[i];
   }

}
